package thread;

public class Task {
    private String name;
    public Task(String name){
        this.name=name;

    }


    public synchronized void methodA() throws InterruptedException {
        System.out.println("这个"+this.name+"A"+"当前线程="+Thread.currentThread().getName()+"正在运行");
        for(int i=0;i<100;i++){
            //Thread.currentThread().interrupt();
            System.out.println(i+Thread.currentThread().getName());
        }
        super.wait(100);
//        Thread.sleep(1000);
        System.out.println("这个"+this.name+"A"+"当前线程="+Thread.currentThread().getName()+"马上退出运行");
    }
    public synchronized void methodB() throws InterruptedException {
        System.out.println("这个"+this.name+"B"+"当前线程="+Thread.currentThread().getName()+"正在运行");
//        super.notify();
        //Thread.sleep(1000);
        System.out.println("这个"+this.name+"B"+"当前线程="+Thread.currentThread().getName()+"马上退出运行");
    }
    public static synchronized void methodC() throws InterruptedException {
        System.out.println("这个C"+"当前线程="+Thread.currentThread().getName()+"正在运行");
        Thread.sleep(1000);
        System.out.println("这个C"+"当前线程="+Thread.currentThread().getName()+"马上退出运行");
    }
    public static synchronized void methodD() throws InterruptedException {
        System.out.println("这个D"+"当前线程="+Thread.currentThread().getName()+"正在运行");
        Thread.sleep(1000);
        System.out.println("这个D"+"当前线程="+Thread.currentThread().getName()+"马上退出运行");
    }
    public static void main(String[] args) {
        Task task=new Task("新task1");
        MyThread1 myThread1=new MyThread1(task);
        MyThread2 myThread2=new MyThread2(task);
//        MyThread3 myThread3=new MyThread3(task);
//        MyThread4 myThread4=new MyThread4(task);
        Thread thread1=new Thread(myThread1,"xiancheng1");
        Thread thread2=new Thread(myThread2);
//        Thread thread3=new Thread(myThread3);
//        Thread thread4=new Thread(myThread4);
        thread1.start();
        thread2.start();
        for(int i=0;i<100;i++){
            System.out.println(i+Thread.currentThread().getName()+"*************");
        }
//        thread3.start();
//        thread4.start();
//        MyThread5 myThread5=new MyThread5(task);
//        myThread5.start();

    }
}
